﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using RabbitMQ.Servers;
using RabbitMQWeb.DB;
using WYYserver_http_api;

namespace RabbitMQ.BLL
{
    /// <summary>
    /// 简单处理业务
    /// </summary>
    public class RabbitMQ_UserInfoBll
    {
        private static string emailAcount = "1484821849@qq.com";//发件人邮箱地址
        public bool SaveUserInfo(RabbitMQ_UserInfo item)
        {
            using (var db = new Entity())
            {
                item.ID = Guid.NewGuid();
                db.RabbitMQ_UserInfo.Add(item);
                db.SaveChanges();
                if (!new Regex(@"^1\d{10}$").IsMatch(item.Tel))
                {
                    throw new Exception("电话号码格式错误!");
                }
                if (!new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$").IsMatch(item.Email))
                {
                    throw new Exception("邮箱格式错误!");
                }
                var count = db.SaveChanges();
                if (count != -1)//写入消息
                {
                    RabbitMQHelper.SendMessage(item, "task_queue", true);
                }
                return db.SaveChanges() != -1;
            }
        }
       


    }
}
